package com.ruoyix.flowable.controller;


import lombok.RequiredArgsConstructor;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyix.common.core.controller.BaseController;
import com.ruoyix.common.core.domain.PageQuery;
import com.ruoyix.common.core.domain.R;
import com.ruoyix.flowable.domain.vo.BpmProcessDefinitionVo;
import com.ruoyix.flowable.domain.bo.BpmProcessDefinitionBo;
import com.ruoyix.flowable.service.IBpmProcessDefinitionService;
import com.ruoyix.common.core.page.TableDataInfo;

/**
 * 流程定义
 *
 * @author ruoyi
 * @date 2023-11-23
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/flowable/processDefinition")
public class BpmProcessDefinitionController extends BaseController {

    private final IBpmProcessDefinitionService iBpmProcessDefinitionService;

    /**
     * 查询流程定义列表
     */
    @SaCheckPermission("flowable:processDefinition:list")
    @GetMapping("/list")
    public TableDataInfo<BpmProcessDefinitionVo> list(BpmProcessDefinitionBo bo, PageQuery pageQuery) {
        return iBpmProcessDefinitionService.queryPageList(bo, pageQuery);
    }

    /**
     * 获取流程定义详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("flowable:processDefinition:query")
    @GetMapping("/{id}")
    public R<BpmProcessDefinitionVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iBpmProcessDefinitionService.queryById(id));
    }

    /**
     * 删除流程定义
     */
    @SaCheckPermission("flowable:processDefinition:remove")
    @GetMapping("/remove")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") String id) {
        return toAjax(iBpmProcessDefinitionService.deleteWithValidByIds(id) ? 1 : 0);
    }

}
